package com.hig.risk.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.hig.risk.domain.RiskSelfInspection;
import com.hig.risk.domain.RiskSelfInspectionContent;
import com.hig.risk.mapper.RiskSelfInspectionContentMapper;
import com.hig.risk.mapper.RiskSelfInspectionMapper;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hig.risk.mapper.RiskSelfInspectionBasisMapper;
import com.hig.risk.domain.RiskSelfInspectionBasis;
import com.hig.risk.service.IRiskSelfInspectionBasisService;

/**
 * 重大隐患判定依据Service业务层处理
 * 
 * @author scp
 * @date 2024-11-29
 */
@Service
public class RiskSelfInspectionBasisServiceImpl implements IRiskSelfInspectionBasisService 
{
    @Autowired
    private RiskSelfInspectionBasisMapper riskSelfInspectionBasisMapper;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private RiskSelfInspectionMapper riskSelfInspectionMapper;

    /**
     * 查询重大隐患判定依据
     * 
     * @param id 重大隐患判定依据ID
     * @return 重大隐患判定依据
     */
    @Override
    public RiskSelfInspectionBasis selectRiskSelfInspectionBasisById(Long id)
    {
        return riskSelfInspectionBasisMapper.selectRiskSelfInspectionBasisById(id);
    }

    /**
     * 查询重大隐患判定依据列表
     * 
     * @param riskSelfInspectionBasis 重大隐患判定依据
     * @return 重大隐患判定依据
     */
    @Override
    public List<RiskSelfInspectionBasis> selectRiskSelfInspectionBasisList(RiskSelfInspectionBasis riskSelfInspectionBasis)
    {
        return riskSelfInspectionBasisMapper.selectRiskSelfInspectionBasisList(riskSelfInspectionBasis);
    }

    /**
     * 新增重大隐患判定依据
     * 
     * @param riskSelfInspectionBasis 重大隐患判定依据
     * @return 结果
     */
    @Override
    public int insertRiskSelfInspectionBasis(RiskSelfInspectionBasis riskSelfInspectionBasis)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        riskSelfInspectionBasis.setCreateBy(loginUser.getUser().getUserName());
        riskSelfInspectionBasis.setDeptId(loginUser.getUser().getDeptId());
        riskSelfInspectionBasis.setCreateTime(DateUtils.getNowDate());
        return riskSelfInspectionBasisMapper.insertRiskSelfInspectionBasis(riskSelfInspectionBasis);
    }

    /**
     * 修改重大隐患判定依据
     * 
     * @param riskSelfInspectionBasis 重大隐患判定依据
     * @return 结果
     */
    @Override
    public int updateRiskSelfInspectionBasis(RiskSelfInspectionBasis riskSelfInspectionBasis)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        riskSelfInspectionBasis.setUpdateBy(loginUser.getUser().getUserName());
        riskSelfInspectionBasis.setUpdateTime(DateUtils.getNowDate());
        return riskSelfInspectionBasisMapper.updateRiskSelfInspectionBasis(riskSelfInspectionBasis);
    }

    /**
     * 批量删除重大隐患判定依据
     * 
     * @param ids 需要删除的重大隐患判定依据ID
     * @return 结果
     */
    @Override
    public int deleteRiskSelfInspectionBasisByIds(Long[] ids)
    {
        return riskSelfInspectionBasisMapper.deleteRiskSelfInspectionBasisByIds(ids);
    }

    /**
     * 删除重大隐患判定依据信息
     * 
     * @param id 重大隐患判定依据ID
     * @return 结果
     */
    @Override
    public int deleteRiskSelfInspectionBasisById(Long id)
    {
        return riskSelfInspectionBasisMapper.deleteRiskSelfInspectionBasisById(id);
    }

    @Override
    public List<RiskSelfInspectionBasis> selectAllBasisList(RiskSelfInspectionBasis riskSelfInspectionBasis) {
        List<RiskSelfInspectionBasis> list = riskSelfInspectionBasisMapper.selectAllBasis(riskSelfInspectionBasis);
        for (RiskSelfInspectionBasis basis : list){
            RiskSelfInspection content = new RiskSelfInspection();
            content.setRemarkSpare(basis.getId().toString());
            List<RiskSelfInspection> contents = riskSelfInspectionMapper.selectContentByBasis(content);
            if (contents != null && contents.size()>0){
                basis.setContentList(contents);
            }else {
                basis.setContentList(new ArrayList<RiskSelfInspection>());
            }
        }
        return list;
    }

    @Override
    public List<RiskSelfInspectionBasis> selectAllBasis(RiskSelfInspectionBasis riskSelfInspectionBasis) {
        return riskSelfInspectionBasisMapper.selectAllBasis(riskSelfInspectionBasis);
    }
}
